package com.central.scheduler.plugin.task.datasource;

import org.apache.commons.collections.MapUtils;

import java.util.Map;
import java.util.regex.Pattern;

/**
 * @author Tindy
 * @date 2021/12/23
 * @describe
 */
public abstract class AbstractDatasourceProcessor implements DatasourceProcessor {

    private static final Pattern IPV4_PATTERN = Pattern.compile("^[a-zA-Z0-9\\_\\-\\.]+$");

    private static final Pattern IPV6_PATTERN = Pattern.compile("^[a-zA-Z0-9\\_\\-\\.\\:\\[\\]]+$");

    private static final Pattern DATABASE_PATTER = Pattern.compile("^[a-zA-Z0-9\\_\\-\\.]+$");

    private static final Pattern PARAMS_PATTER = Pattern.compile("^[a-zA-Z0-9\\-\\_\\/]+$");


    /**
     * check database name is valid
     *
     * @param database database name
     */
    protected void checkDatasourcePatter(String database) {
        if (!DATABASE_PATTER.matcher(database).matches()) {
            throw new IllegalArgumentException("datasource name illegal");
        }
    }
}
